Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc] Fix statfs_to_statvfs conversion function on rv32 #98098

Merged
merged 1 commit into from
Jul 9, 2024

Conversation

mikhailramalho
Copy link
Member

This patch fixes implicit conversion loses integer precision warnings by adding explicit casts. Should be NFC for 64-bit systems.

This patch fixes implicit conversion loses integer precision warnings by
adding explicit casts. Should be NFC for 64-bit systems.
@llvmbot
Copy link
Collaborator

llvmbot commented Jul 8, 2024

@llvm/pr-subscribers-libc

Author: Mikhail R. Gadelha (mikhailramalho)

Changes

This patch fixes implicit conversion loses integer precision warnings by adding explicit casts. Should be NFC for 64-bit systems.


Full diff: https://github.com/llvm/llvm-project/pull/98098.diff

1 Files Affected:

  • (modified) libc/src/sys/statvfs/linux/statfs_utils.h (+9-8)
diff --git a/libc/src/sys/statvfs/linux/statfs_utils.h b/libc/src/sys/statvfs/linux/statfs_utils.h
index 606786a571838..52f810d702d2a 100644
--- a/libc/src/sys/statvfs/linux/statfs_utils.h
+++ b/libc/src/sys/statvfs/linux/statfs_utils.h
@@ -77,14 +77,15 @@ LIBC_INLINE struct statvfs statfs_to_statvfs(const LinuxStatFs &in) {
   struct statvfs out;
   out.f_bsize = in.f_bsize;
   out.f_frsize = in.f_frsize;
-  out.f_blocks = in.f_blocks;
-  out.f_bfree = in.f_bfree;
-  out.f_bavail = in.f_bavail;
-  out.f_files = in.f_files;
-  out.f_ffree = in.f_ffree;
-  out.f_favail = in.f_ffree;
-  out.f_fsid = in.f_fsid.val[0] |
-               static_cast<decltype(out.f_fsid)>(in.f_fsid.val[1]) << 32;
+  out.f_blocks = static_cast<decltype(out.f_blocks)>(in.f_blocks);
+  out.f_bfree = static_cast<decltype(out.f_bfree)>(in.f_bfree);
+  out.f_bavail = static_cast<decltype(out.f_bavail)>(in.f_bavail);
+  out.f_files = static_cast<decltype(out.f_files)>(in.f_files);
+  out.f_ffree = static_cast<decltype(out.f_ffree)>(in.f_ffree);
+  out.f_favail = static_cast<decltype(out.f_favail)>(in.f_ffree);
+  out.f_fsid = in.f_fsid.val[0];
+  if constexpr (sizeof(decltype(out.f_fsid)) == sizeof(uint64_t))
+    out.f_fsid |= static_cast<decltype(out.f_fsid)>(in.f_fsid.val[1]) << 32;
   out.f_flag = in.f_flags;
   out.f_namemax = in.f_namelen;
   return out;

@SchrodingerZhu SchrodingerZhu merged commit c1f1aab into llvm:main Jul 9, 2024
6 of 7 checks passed
@mikhailramalho mikhailramalho deleted the fix-statfs-to-statvfs branch July 9, 2024 19:29
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants